package goiot.api;

import com.fasterxml.jackson.core.type.TypeReference;

import goiot.GoiotHttp;
import goiot.dto.JsonResp;
import goiot.dto.LoginForm;

public class LoginApi {
	private static final TypeReference<JsonResp<String>> STRING_REF = new TypeReference<JsonResp<String>>() {};

	public LoginApi() {
	}
	
	public JsonResp<String> login(LoginForm form) {
		JsonResp<String> resp = GoiotHttp.post("/api/login", form, STRING_REF);
		if (Boolean.TRUE.equals(resp.getSuccess())) {
			GoiotHttp.setToken(resp.getResult());
		}
		return resp;
	}
	
	public JsonResp<String> tokenRefresh() {
		JsonResp<String> jsonResp = GoiotHttp.get("api/token/refresh", STRING_REF);
		return jsonResp;
	}
	
}
